package com.sanpu.kxe.business.trade.view;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sanpu.kxe.R;
import com.sanpu.kxe.base.BaseTitleActivity;
import com.sanpu.kxe.business.trade.bean.MyDividendOutput;
import com.sanpu.kxe.business.trade.contract.MyProfitContract;
import com.sanpu.kxe.business.trade.presenter.MyProfitPresenter;
import com.sanpu.kxe.module.immersionbar.ImmersionBar;
import com.sanpu.kxe.utils.SystemBarHelper;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Description：我的分红
 * Created by 薛勇军 on 2019/6/27.
 */

public class MyProfitActivity extends BaseTitleActivity implements MyProfitContract.View {

    @Bind(R.id.totalDividendTv)
    TextView totalDividendTv;
    @Bind(R.id.originalVipDividendTv)
    TextView originalVipDividendTv;
    @Bind(R.id.nationalDividendTv)
    TextView nationalDividendTv;
    @Bind(R.id.equityDividendTv)
    TextView equityDividendTv;
    @Bind(R.id.boleRewardTv)
    TextView boleRewardTv;
    @Bind(R.id.headerView)
    RelativeLayout headerView;

    private MyProfitContract.Presenter mPresenter;

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_my_profit;
    }

    @Override
    protected void initView() {
        super.initView();
        int barHeight = SystemBarHelper.getStatusBarHeight(getContext());
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) headerView.getLayoutParams();
        params.setMargins(0, barHeight, 0, 0);
        headerView.setLayoutParams(params);

        mPresenter = new MyProfitPresenter(this);
        mPresenter.myDividend();
    }

    @Override
    protected void setListener() {
        super.setListener();
        ButterKnife.findById(this, R.id.leftIv).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    public void showDataView(MyDividendOutput output) {
        if (output != null) {
            if (!TextUtils.isEmpty(output.getTotalDividend())) {
                totalDividendTv.setText(output.getTotalDividend());
            }
            if (!TextUtils.isEmpty(output.getOriginalVipDividend())) {
                originalVipDividendTv.setText(output.getOriginalVipDividend());
            }
            if (!TextUtils.isEmpty(output.getNationalDividend())) {
                nationalDividendTv.setText(output.getNationalDividend());
            }
            if (!TextUtils.isEmpty(output.getEquityDividend())) {
                equityDividendTv.setText(output.getEquityDividend());
            }
            if (!TextUtils.isEmpty(output.getBoleReward())) {
                boleRewardTv.setText(output.getBoleReward());
            }
        }
    }

    @Override
    protected void initImmersionBar() {
        mImmersionBar = ImmersionBar.with(this);
        mImmersionBar.statusBarColorTransformEnable(true)
                .navigationBarWithKitkatEnable(false)
                .init();
    }

    @Override
    protected boolean hasBindEventBus() {
        return false;
    }

    @Override
    protected boolean hasCommonTitle() {
        return false;
    }

    @Override
    public void setPresenter(MyProfitContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public Context getContext() {
        return this;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.onDestroyPresenter();
            mPresenter = null;
        }
    }
}
